
# ifndef __DFX_VECTOR2_H__
# define __DFX_VECTOR2_H__

# include "dfxCore.h"

namespace DFX
{
    class DFX_EXPORT Vector2
    {
    public:

        Float32 X, Y;

    public:

        Vector2(Float32 f = 0.0f)
            : X(f), Y(f)
        {
        }

        Vector2(Float32 x, Float32 y)
            : X(x), Y(y)
        {
        }

        Vector2(const Vector2 &v)
            : X(v.X), Y(v.Y)
        {
        }

        inline Float32 GetLengthSqr() const 
        {
            return X * X + Y * Y;
        }

        inline Float32 GetLength() const
        {
            return sqrtf(X * X + Y * Y);
        }

        inline void Normalize()
        {
            Float32 length = sqrtf(X * X + Y * Y);
            
            if (length != 0.0f)
            {
                Float32 invLen = 1.0f / length;

                X *= invLen;
                Y *= invLen;
            }            
        }

        inline Vector2 operator - () const
        {
            return Vector2(-X, -Y);
        }

        inline Vector2 operator + (const Vector2 &v) const
        {
            return Vector2(X + v.X, Y + v.Y);
        }

        inline Vector2 operator - (const Vector2 &v) const
        {
            return Vector2(X - v.X, Y - v.Y);
        }

        inline Vector2 operator * (float f) const
        {
            return Vector2(X * f, Y * f);
        }

        inline Vector2 operator / (float f) const
        {
            return Vector2(X / f, Y / f);
        }

        inline Vector2& operator += (const Vector2 &v)
        {
            X += v.X;
            Y += v.Y;

            return *this;
        }

        inline Vector2& operator -= (const Vector2 &v)
        {
            X += v.X;
            Y += v.Y;

            return *this;
        }

        inline Vector2& operator *= (float f)
        {
            X *= f;
            Y *= f;

            return *this;
        }

        inline Vector2& operator /= (float f)
        {
            X /= f;
            Y /= f;

            return *this;
        }

        inline bool operator == (const Vector2 &v)
        {
            return X == v.X && Y == v.Y;
        }

        inline bool operator != (const Vector2 &v)
        {
            return X != v.X || Y != v.Y;
        }
    };
}

# endif